﻿<%@ Page Language="C#" AutoEventWireup="false" CodeFile="recDevolutionform.aspx.cs" Inherits="SIPO.Web.Forms.Transaction.recDevolutionform" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.inputmask.bundle.min.js") %>" type="text/javascript"></script>

    <script src="<%= ResolveUrl("~/scripts/plupload/moxie.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/plupload/plupload.full.min.js") %>" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            //mengupload file
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight',
                browse_button: 'pickfiles',
                container: 'container',
                max_file_size: '5mb',
                url: '<%= ResolveUrl("~/AjaxHandler/Transaction/recDevolutionhandler.ashx") %>' + '?method=update',
                flash_swf_url: '<%= ResolveUrl("~/scripts/plupload/Moxie.swf") %>',
                silverlight_xap_url: '<%= ResolveUrl("~/scripts/plupload/Moxie.swf") %>',
                filters: [
            { title: "Pdf files", extensions: "pdf" },
            { title: "Excel files", extensions: "xls,xlsx" },
			{ title: "Text files", extensions: "txt" },
			{ title: "Image files", extensions: "jpeg,jpg,gif,png" },
            { title: "Word files", extensions: "doc,docx" },
			{ title: "PowerPoint files", extensions: "ppt,pptx" }
		],
                resize: { width: 320, height: 240, quality: 90 }
            });


            uploader.bind('Init', function (up, params) {

                var msg = 'Untuk dapat melakukan proses unggah / upload dokumen, browser anda harus mendukung salah satu teknologi, HTML 5 / Flash / Silverlight';

                if (params.runtime == 'html5') {
                    msg = '';
                } else if (params.runtime == 'flash') {
                    msg = '';
                } else if (params.runtime == 'silverlight') {
                    msg = ''
                }

                if (msg != '') {
                    alert(msg);
                }

            });

            uploader.init();

            uploader.bind('FilesAdded', function (up, files) {

                if (up.files.length > 1) {
                    alert('Hanya diperbolehkan satu file untuk di upload!');
                    return false;
                }

                $.each(files, function (i, file) {
                    $('#filelist').append(
                        '<div id="' + file.id + '">' +
                file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' + '</div>');
                });

                up.refresh(); // Reposition Flash/Silverlight
            });

            uploader.bind('FileUploaded', function (up, file, info) {

                var err = JSON.parse(info.response);
                alert(err.Message);

            });

            uploader.bind('Error', function (up, err) {

                var errMsg = '';

                switch (err.code) {
                    case (-600):
                        errMsg = 'File tidak boleh lebih dari 5 Mb';
                        break;
                    case (-601):
                        errMsg = 'File harus berformat excel / word/ text / pdf / gambar';
                        break;
                    default:
                        errMsg = err.code + ' - ' + err.message;
                        break;
                }

                alert(errMsg);

                up.refresh(); // Reposition Flash/Silverlight

            });

            $("#btnCancel").button({ icons: { primary: "ui-icon-close"} });
            $("#btnSubmit").button({ icons: { primary: "ui-icon-disk"} });

            //disabled control
            //            $('#txtDebtorId').attr('disabled', 'disabled');
            //            $('#txtLetterNo').attr('disabled', 'disabled');
            //            $('#txtLetterDate').attr('disabled', 'disabled');
            //            $('#txtDevolutionValues').attr('disabled', 'disabled');

            //format tanggal
            $('#txtLetterDate').datepicker({ showWeek: true, showButtonPanel: true,
                changeMonth: true,
                changeYear: true,
                dateFormat: 'dd/mm/yy',
                minDate: 0
            });

            $('#txtLetterDate').inputmask("d/m/y", { "placeholder": "dd/mm/yyyy" });

            $('#txtDevolutionDate').datepicker({ showWeek: true, showButtonPanel: true,
                changeMonth: true,
                changeYear: true,
                dateFormat: 'dd/mm/yy',
                minDate: 0
            });

            $('#txtDevolutionDate').inputmask("d/m/y", { "placeholder": "dd/mm/yyyy" });

            //format uang
            $("#txtDevolutionValues").inputmask("decimal", { radixPoint: ",", autoGroup: true, groupSeparator: ".", groupSize: 3, digits: 2, repeat: 18 });

            $('#ddlDebtorName').change(function () {
                var debtorId = $('#ddlDebtorName').val();
                $('#txtDebtorId').val(debtorId)
                var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/Loaddata/getDemandForDebtorName.ashx") %>';

                //ambil data recDemand berdasarkan debtorName
                jQuery.ajax({
                    type: 'POST',
                    url: handlerUrl + '?DebtorID=' + debtorId,
                    contentType: 'application/json',
                    dataType: 'json',
                    success: function (data) {
                        $('#hfDemandNo').val(data.DemandNo);
                        $('#hfDebtorName').val(data.DebtorName);
                        $('#txtLetterNo').val(data.LatterNo);
                        $('#txtLetterDate').val(data.LatterDate);
                        $('#txtDevolutionValues').val(data.TransValue);
                    },
                    error: function () {
                        alert('Error getDemandForDebtorName !');
                    }
                });
            });

            $('#btnCancel').click(function () {
                parent.$('#dialog1').dialog('close');

                return false;
            });

            $('#btnSubmit').click(function (e) {
                e.preventDefault();
                var demandNo = $('#hfDemandNo').val();
                //mengupload file
                if ($('#hfId').val() > 0) {
                    aksiSimpan('update');
                } else {
                    aksiSimpan('insert');
                }

            });

            function aksiSimpan(aksi) {
                if (uploader.files.length > 0) // Insert with uploaded file.
                {
                    uploader.settings.multipart_params = {
                        'hfId': encodeURIComponent($('#hfId').val()),
                        'hfDemandNo': encodeURIComponent($('#hfDemandNo').val()),
                        'hfDebtorName': encodeURIComponent($('#hfDebtorName').val()),
                        'txtDebtorId': encodeURIComponent($('#txtDebtorId').val()),
                        'txtLetterNo': encodeURIComponent($('#txtLetterNo').val()),
                        'txtLetterDate': encodeURIComponent($('#txtLetterDate').val()),
                        'txtDevolutionDate': encodeURIComponent($('#txtDevolutionDate').val()),
                        'txtDevolutionValues': encodeURIComponent($('#txtDevolutionValues').val()),
                        'txtCatatan': encodeURIComponent($('#txtCatatan').val())

                    };

                    uploader.settings.url = '<%= ResolveUrl("~/AjaxHandler/Transaction/recDevolutionhandler.ashx") %>' + '?method=' + aksi;
                    uploader.start();
                }
                else {

                    $.post('<%= ResolveUrl("~/AjaxHandler/Transaction/recDevolutionhandler.ashx") %>' + '?method=' + aksi,
                                $("#form1")
                                .find("input,textarea,select,hidden")
                                .not("#__VIEWSTATE,#__EVENTVALIDATION")
                                .serialize())
                            .done(function (data) {
                                var r = JSON.parse(data);
                                alert(data.Message);
                            })
                            .fail(function () {
                                alert('Data gagal di ' + aksi);
                            });

                }

                parent.$('#dialog1').dialog('close');
                setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);

                return false;
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
            <tr>
                <td>Nama Debitur</td>
                <td>:</td>
                <td>
                    <asp:DropDownList ID="ddlDebtorName" runat="server">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>ID Debitur</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtDebtorId" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Nomor Surat Pelimpahan</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtLetterNo" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Tgl. Surat Pelimpahan</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtLetterDate" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                <br />
                </td>
            </tr>
            <tr>
                <td>Tgl. Pelimpahan</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtDevolutionDate" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Jumlah Pelimpahan</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtDevolutionValues" runat="server" style="text-align:right"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Catatan</td>
                <td>:</td>
                <td>
                    <asp:TextBox ID="txtCatatan" runat="server" TextMode="MultiLine"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Lampiran</td>
                <td>:</td>
                <td>
                    <div id="container">
                    <a id="pickfiles" class="plupload_button plupload_add ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                        href="#"><span class="ui-button-icon-primary ui-icon ui-icon-circle-plus" /><span
                            class="ui-button-text">Add Files</span> </a>
                    <br />
                    <div id="filelist"></div>
                </div>
                </td>
            </tr>
            <tr align="right">
                <td colspan="3">
                <br />
                
                    <button id="btnSubmit" type="submit" runat="server">
                        Simpan</button>
                    <button id="btnCancel" type="button">
                        Batal</button>
                    
                </td>
            </tr>
            <tr>
                <td>
                    <asp:HiddenField ID="hfId" runat="server" />
                    <asp:HiddenField ID="hfDebtorName" runat="server" />
                    <asp:HiddenField ID="hfDemandNo" runat="server" />
                </td>
            </tr>
          </table>
    </div>
    </form>
</body>
</html>
